<template>
  <div/>

</template>

<script>
export default {
  name: 'BaseEchartBarSingle',
  components: { },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    charDivId: {
      type: String,
      required: true
    },
    valeDesc: {
      type: String,
      default: ''
    },
    datas: Array
  },
  data() {
    return {
      myChart: {},
      // chartdata: {
      //   legendData: [],
      //   seriesData: []
      // },
      option: {
        tooltip: {
          trigger: 'axis',
          axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
          // name: this.valeDesc //太挤
        },
        yAxis: {
          type: 'category'
        // data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        series: [
          {
            type: 'bar',
            barWidth: 25, // 柱图宽度
            label: {
              show: true,
              position: 'right'
              // position: 'inside'
            }
            // data: [320, 302, 301, 334, 390, 330, 320]
          }
        ]
      }
    }
  },
  watch: {
    'datas': function() {
      this.draw()
    }
  },
  mounted: function() {
    this.init()
  },
  methods: {
    initChar(gas, water) {
      console.log(gas)
      console.log(water)
      // 基于准备好的dom，初始化echarts实例
      this.myChart = this.$echarts.init(document.getElementById(this.charDivId))
    },
    draw() {
      const chartArray = this.datas
      if (chartArray && chartArray instanceof Array && chartArray.length > 0) {
        const yAxisData = []
        const seriesData = []

        for (let i = 0; i < chartArray.length; i++) {
          yAxisData.unshift(chartArray[i]['name'])
          seriesData.unshift(chartArray[i]['value'])
        }
        this.option.yAxis.data = yAxisData
        this.option.series[0].data = seriesData
        this.myChart.setOption(this.option, true)
      }
    },
    init() {
      this.initChar()
      // this.draw()
    }
  }
}
</script>

<style scoped>

.cardRadius {
  border-radius: 15px;
}
.verticalDivider {
  margin-top: 5%;
  margin-bottom: 5%;
  border: 2px solid #e6ebef;
}
div {
  margin: 0px;
  padding: 0px;
}
</style>
